package com.crm.common;

import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.util.Properties;

import org.apache.log4j.Logger;

public class CrmInit {

	private static Logger logger = Logger.getLogger(CrmInit.class);

	private static final String CRM_PROP_PATH = "crm.properties";

	private static final Properties properties;

	static {
		logger.info("Begin init CrmInit from file " + CRM_PROP_PATH);
		// 1:加载配置文件
		properties = new Properties();
		try {
			properties.load(new InputStreamReader(CrmInit.class.getClassLoader().getResourceAsStream(CRM_PROP_PATH),
					"UTF-8"));
		} catch (Exception e) {
			logger.error("CrmInit.init has error:", e);
			throw new RuntimeException(MessageFormat.format(
					"CrmInit.init has error: file [{0}] not found in classpath.", CRM_PROP_PATH));
		}
		// 2:给全局变量赋值
		CrmInit.DB_NAME = properties.getProperty("db.name");
		CrmInit.DB_USERNAME = properties.getProperty("db.username");
		CrmInit.DB_PASSWORD = properties.getProperty("db.password");
		CrmInit.DB_BACKUP_EXP = properties.getProperty("db.backup.exp");
		CrmInit.DB_BACKUPBIN_PATH = properties.getProperty("db.backupbin.path");
		CrmInit.DB_BACKUPSTORE_PATH = properties.getProperty("db.backupstore.path");
		CrmInit.UPLOAD_PATH = properties.getProperty("upload.path");

		CrmInit.MAIL_HOST = properties.getProperty("mail.host");
		CrmInit.MAIL_MASTER = properties.getProperty("mail.master");
		CrmInit.MAIL_RECEIVE = properties.getProperty("mail.receive");
		CrmInit.MAIL_PASSWORD = properties.getProperty("mail.password");
		CrmInit.MAIL_TITLE = properties.getProperty("mail.title");
		CrmInit.MAIL_CONTEXT = properties.getProperty("mail.context");
	}

	public static String DB_NAME;

	public static String DB_USERNAME;

	public static String DB_PASSWORD;

	public static String DB_BACKUP_EXP;

	public static String DB_BACKUPBIN_PATH;

	public static String DB_BACKUPSTORE_PATH;

	public static String UPLOAD_PATH;

	public static String MAIL_HOST;

	public static String MAIL_MASTER;

	public static String MAIL_RECEIVE;

	public static String MAIL_PASSWORD;

	public static String MAIL_TITLE;

	public static String MAIL_CONTEXT;

}
